package com.xaicode.template.gendata.common;

import java.util.Date;
import java.util.Random;

/**
 * @author Locker xaicode@sina.com
 * @version 1.0
 * @date 2022/5/24 0024 20:26
 */
public class RandomDate {

    Long logDateTime = 0L;
    int maxTimeStep = 0;

    public RandomDate(Date startDate, Date endDate, int num) {
        long avgStepTime = (endDate.getTime() - startDate.getTime()) / num;
        this.maxTimeStep = (int) avgStepTime * 2;
        this.logDateTime = startDate.getTime();
    }

    public Date getRandomDate() {
        int timeStep = (new Random()).nextInt(this.maxTimeStep);
        this.logDateTime = this.logDateTime + timeStep;
        return new Date(this.logDateTime);
    }

}
